<?php

//get all product
function getAllProduct(){
	$qr ="SELECT * FROM product";
	return mysql_query($qr);
}

//get top 20 product which highest revenue
function getTop20Product(){
		$qr ="SELECT * 
		FROM  `product` 
		ORDER BY ProductAmountTotal DESC 
		LIMIT 0 , 20";
	return mysql_query($qr);
}

//add product	
function addProduct($productName,$subCategoryID,$price,$unit,$image,$description){
	$qr ="INSERT INTO product(ProductName,SubCategoryID,Price,Unit,Image,Description) VALUES('$productName','$subCategoryID','$price','$unit','$image','$description')";
	mysql_query($qr);
}

//get product by id	
function getProductByID($productID){
	$qr ="SELECT * FROM product WHERE ProductID = $productID;";
	return mysql_query($qr);
}

//get list product	by subcategoryid
function getListProductBySubCategoryID($subCategoryID){
	$qr ="SELECT * FROM product WHERE SubCategoryID = $subCategoryID;";
	return mysql_query($qr);
}

//edit product	
function editProduct($productName,$subCategoryID,$price,$unit,$image,$description,$productID){
	$qr ="UPDATE product 
	SET 
	ProductName = '$productName',
	SubCategoryID = '$subCategoryID',
	Price = '$price',
	Unit = '$unit',
	Image = '$image',
	Description = '$description'
	WHERE ProductID = $productID; ";
	mysql_query($qr);
}

//edit product	
function editProductAmountTotal($productAmountTotal,$productID){
	$qr ="UPDATE product 
	SET 
	ProductAmountTotal = '$productAmountTotal'
	WHERE ProductID = $productID; ";
	mysql_query($qr);
}

//delete product	
function deleteProduct($productID){
	$qr ="DELETE FROM product WHERE ProductID = $productID";
	mysql_query($qr);
}


?>